<?php

declare(strict_types=1);

namespace RX\Exception;

use Exception;
use Throwable;

class BizException extends Exception
{
    /**
     * @var string
     */
    private string $realCode;

    /**
     * @var string
     */
    private string $realMessage;

    public function __construct($class, $code, string $message = null, Throwable $previous = null)
    {
        if (is_null($message)) {
            $message = (new $class())->getMessage($code);
        }
        $this->realCode    = $code;
        $this->realMessage = $previous ? $previous->getMessage() : $message;
        parent::__construct($message, 0, $previous);
    }

    public function getRealCode(): string
    {
        return $this->realCode;
    }

    public function getRealMessage(): string
    {
        return $this->realMessage;
    }
}
